package net.hserver.gateway.config;


import cn.hserver.core.ioc.annotation.Bean;
import cn.hserver.core.server.util.ExceptionUtil;
import cn.hserver.core.server.util.JsonResult;
import cn.hserver.plugin.web.context.Webkit;
import cn.hserver.plugin.web.interfaces.GlobalException;

@Bean
public class WebException implements GlobalException {

  @Override
  public void handler(Throwable throwable, int httpStatusCode, String errorDescription, Webkit webkit) {
    throwable.printStackTrace();
    System.out.println(webkit.httpRequest.getUri() + "--->" + throwable.getMessage());
    JsonResult result = JsonResult.error("发生了一个错误");
    result.put("success",false);
    result.put("data", ExceptionUtil.getMessage(throwable));
    webkit.httpResponse.sendJson(result);
  }
}